package gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JScrollPane;
import javax.swing.JList;
import model.Guest;
import model.Room;
import ctr.Gctr;
import ctr.RRctr;

public class RRCreateRoomReservation extends JFrame {

	private JPanel contentPane;
	private JList lstGuests;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					RRCreateRoomReservation frame = new RRCreateRoomReservation();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public RRCreateRoomReservation() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 703, 482);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JButton btnStartside = new JButton("StartSide");
		btnStartside.setBounds(0, 30, 133, 25);
		contentPane.add(btnStartside);
		
		JButton btnNewButton = new JButton("RoomReservation");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		btnNewButton.setBounds(0, 54, 133, 25);
		contentPane.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("FacilityReservation");
		btnNewButton_1.setBounds(0, 78, 133, 25);
		contentPane.add(btnNewButton_1);
		
		JButton btnNewButton_2 = new JButton("Hire Instuctor");
		btnNewButton_2.setBounds(0, 102, 133, 25);
		contentPane.add(btnNewButton_2);
		
		JButton btnShow = new JButton("show");
		btnShow.setBounds(0, 126, 133, 25);
		contentPane.add(btnShow);
		
		JButton btnNew = new JButton("new");
		btnNew.setBounds(0, 150, 133, 25);
		contentPane.add(btnNew);
		
		JButton btnNewButton_3 = new JButton("Show Available");
		btnNewButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		btnNewButton_3.setBounds(0, 174, 133, 25);
		contentPane.add(btnNewButton_3);
		
		JButton btnNewButton_4 = new JButton("Create Guest");
		btnNewButton_4.setBounds(0, 198, 133, 25);
		contentPane.add(btnNewButton_4);
		
		JButton btnCreateReservation = new JButton("Create Reservation");
		btnCreateReservation.setBounds(0, 222, 133, 25);
		contentPane.add(btnCreateReservation);
		
		JButton btnAddRoom = new JButton("Add Room");
		btnAddRoom.setBounds(0, 246, 133, 25);
		contentPane.add(btnAddRoom);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(131, 0, 554, 385);
		contentPane.add(scrollPane);
		
		 lstGuests = new JList();
		scrollPane.setViewportView(lstGuests);
		
		JButton btnUpdateList = new JButton("Update List");
		btnUpdateList.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				updateGuestList();
			}
		});
		btnUpdateList.setBounds(576, 398, 97, 25);
		contentPane.add(btnUpdateList);
		
		JButton btnChoseGuest = new JButton("Chose Guest");
		btnChoseGuest.setBounds(464, 398, 103, 25);
		contentPane.add(btnChoseGuest);
	}
	
	private void updateGuestList()
	{
		ArrayList<Guest> list = new Gctr().findAllGuests();
		DefaultListModel<Guest> dlist = new DefaultListModel<>();
		for(Guest guest: list)
			dlist.addElement(guest);
		lstGuests.setModel(dlist);
	}
	
	private void makePartOrder()
	{
		Guest o = (Guest)this.lstGuests.getSelectedValue();
		//JOptionPane.showConfirmDialog(null, o);
		////od.setVisible(true);
		
	}

}
